package com.mianyang.zhangsan.plugin.quartz;

import com.alibaba.fastjson.JSONObject;
import com.mianyang.zhangsan.common.util.JsonUtils;
import com.mianyang.zhangsan.model.entity.SecTask;
import org.quartz.*;
import org.quartz.impl.StdScheduler;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author jiangjr
 * @date 2022-11-19
 */
public class Client {

    public static void main(String[] args) throws SchedulerException {
//        createTask();
        SecTask task = new SecTask();
        task.setTaskId(1L);
        task.setTaskGroup("group");
        task.setTaskName("你好 china");
        task.setTaskTime("2022-10-11 18:09:00");
        task.setTaskType(1);
        String json = JSONObject.toJSONString(task);
        System.out.println("序列化-" + json);
        SecTask bean = JsonUtils.toBean(json, SecTask.class);
        System.out.println("反序列化-" + bean);
    }

    private static void createTask() throws SchedulerException {
        // 构建任务
        JobDetail jobDetail = JobBuilder.newJob(SecQuartzJob.class)
                .withIdentity("compute", "test")
                .build();
        // 创建触发器
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("compute", "test")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInHours(10)
                        .repeatForever())
                .build();
        // 创建调度器
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();
    }
}
